<?php
// 检查打卡积分菜单
$host = '127.0.0.1';
$port = 3306;
$database = 'qiandao';
$username = 'root';
$password = 'root';

try {
    $pdo = new PDO("mysql:host={$host};port={$port};dbname={$database};charset=utf8mb4", $username, $password);
    $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
    
    echo "=== 检查打卡积分菜单 ===\n\n";
    
    // 查询所有一级菜单
    echo "1. 所有一级菜单:\n";
    $stmt = $pdo->query("SELECT id, title, status, sort FROM system_menu WHERE pid = 0 ORDER BY sort DESC, id ASC");
    $topMenus = $stmt->fetchAll(PDO::FETCH_ASSOC);
    foreach ($topMenus as $menu) {
        echo "  ID:{$menu['id']} {$menu['title']} (状态:{$menu['status']}, 排序:{$menu['sort']})\n";
    }
    
    // 查询打卡积分的子菜单
    echo "\n2. 打卡积分的子菜单:\n";
    $stmt = $pdo->query("SELECT id, pid, title, node, status, sort FROM system_menu WHERE title LIKE '%打卡%' OR title LIKE '%会员%' OR title LIKE '%礼品%' OR node LIKE 'checkin/%' ORDER BY pid, sort DESC, id ASC");
    $checkinMenus = $stmt->fetchAll(PDO::FETCH_ASSOC);
    
    if (empty($checkinMenus)) {
        echo "  ✗ 没有找到打卡积分相关菜单！\n";
    } else {
        foreach ($checkinMenus as $menu) {
            $level = $menu['pid'] == 0 ? '一级' : ($menu['pid'] < 26 ? '二级' : '三级');
            echo "  [{$level}] ID:{$menu['id']} PID:{$menu['pid']} {$menu['title']} (node:{$menu['node']}, 状态:{$menu['status']}, 排序:{$menu['sort']})\n";
        }
    }
    
    echo "\n3. 菜单总数:\n";
    $stmt = $pdo->query("SELECT COUNT(*) FROM system_menu WHERE status = 1");
    $count = $stmt->fetchColumn();
    echo "  启用的菜单总数: {$count}\n";
    
} catch (PDOException $e) {
    echo "错误: " . $e->getMessage() . "\n";
}

